package com.warm.orm.domain;

import com.easy.query.api4j.select.Queryable;
import com.warm.core.page.PageDomain;

import cn.hutool.core.text.CharSequenceUtil;
import lombok.Getter;
import lombok.Setter;

/**
 * 分页数据
 *
 * @author warm
 */
@Getter
@Setter
public class QueryParam<T> extends PageDomain {
    public static <T> PageDomain getPage(QueryParam<T> queryParam) {
        PageDomain page = new PageDomain();
        page.setPageNum(queryParam.getPageNum());
        page.setPageSize(queryParam.getPageSize());
        return page;
    }

    public static <T> PageDomain getPage(QueryParam<T> queryParam, Queryable<T> query) {
        query.orderByObject(CharSequenceUtil.isNotBlank(queryParam.getOrderBy()), new PropertySort(
            queryParam.getOrderBy(), !CharSequenceUtil.equalsIgnoreCase(queryParam.getIsAsc(), "desc")));

        return getPage(queryParam);
    }

}
